<?php
namespace App\Services\PingAnPay;

//header("Content-Type: text/html;charset=gbk");
        const SEND_URL = 'https://testebank.sdb.com.cn:461/corporbank/KH0001.pay';


require_once 'lib/pingan.php';
$pingan = new pingan();

$data = array(
    'masterId' => '2000311146',
    'orderId' => $_POST['order_id'],
);


$xml_data = $pingan->array_to_xml($data);
$merchantCertFile = 'merchant/2000311146.pfx';

//获取签名后的orig和sign
$orig = $pingan->getOrig($xml_data);
$sign = $pingan->getSign($merchantCertFile, $xml_data);

//通过curl请求接口
$parms = 'orig=' . $orig . '&sign=' . $sign;
$rsponse = $pingan->curl(SEND_URL, $parms);

//通过字符串截取获取orig
$rsponseData = explode('orig=', $rsponse);
$rsponse2Data = explode('SDBPAYGATE=', $rsponseData[1]);

//解码
$formOrig = $pingan->_base64_url_decode($rsponse2Data[0]);

//$xml_dom = str_replace("GBK", "utf-8", $formOrig);
//$result = $pingan->xml_to_array($xml_dom);
//输出结果
echo '<?xml version="1.0" encoding="GBK"?>';
echo $formOrig;
die('this is gbk!please check result by console');
?>